<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
</head>
<body>   
<table id="ur_dg"></table>
<script type="text/javascript">
var ur_dg;
ur_dg=$('#ur_dg').datagrid({    
    url:'${ctx}/system/role/json', 
    fit : true,
	fitColumns : true,
	border : false,
	idField : 'id',
	rownumbers:true,
    columns:[[    
		{field:'ck',checkbox:true},  
        {field:'id',title:'id',hidden:true},    
        {field:'name',title:'角色名称',sortable:true},
        {field:'description',title:'角色描述',sortable:true,width:50}
    ]],
    onLoadSuccess:function(){
    	//获取用户拥有角色,选中
    	$.ajax({
    		async:false,
			type:'get',
			url:"${ctx}/system/user/${userId}/roleJson",
			success: function(data){
				if(data){
					for(var i=0,j=data.length;i<j;i++){
						ur_dg.datagrid('selectRecord',data[i]);
					}
				} 
			}
		});
    	
    }
	});

//弹窗添加
function saveUserRole(){
	var newRoleList=[];
	var data=ur_dg.datagrid('getSelections');
	for(var i=0,j=data.length;i<j;i++){
		newRoleList.push(data[i].id);
	}
	$.ajax({
		async:false,
		type:'POST',
		data:JSON.stringify(newRoleList),
		contentType:'application/json;charset=utf-8',	//必须
		url:"${ctx}/system/user/${userId}/updateRole",
		success: function(data){
			if(data=='success'){
				parent.$.messager.show({ title : "提示",msg: "操作成功！", position: "bottomRight" });
			}else{
				$.easyui.messager.alert(data);
			}
		}
	});
}
</script>
</body>
</html>